package com.comm.tmpl.service;

import java.util.List;
import java.util.Map;

import jcf.hanyang.dao.CommonDAO;
import jcf.sua.dataset.GridData;
import jcf.sua.dataset.RowStatus;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.comm.tmpl.model.WordDeungrok;
import com.comm.tmpl.qry.WordDeungrokQry;
import com.comm.tmpl.qry.WordDeungrokQry2;

/**
 * 단어사전 목록을 조회, 등록,수정, 삭제 저장하는 서비스
 * @Author : 최성원
 * @Company : Daewoo Information Systems Co., Ltd.
 * @Copyright : Daewoo Information Systems Co., Copyright (c) 2010
 * @Create : 2011년 8월 2일
 * @DSDM_UML20_PROFILE_x__y_Service_x__y_Class_ID WordDeungrokSvc
 * @Title : 단어사전등록 서비스
 * @stereotype Service
 * @version 1.0
 */
@Service
public class WordDeungrokSvc {
	/*#com.comm.tmpl.model.WordDeungrok wordDeungrok*/
	
	@Autowired(required=false)
	private CommonDAO dao;
	
	/**
     * 단어사전 목록 조회
     * @Author : 최성원
     * @Create : 2011년 5월 10일
     * @Description : 산어사전 목로을 조회한다.
     * @Title : 단어사전 목록조회 메소드
     * @DSDM_UML20_PROFILE_x__y_ServiceMethod_x__y_IF WordDeungrokQry.selectWord()
     * @stereotype ServiceMethod 
     */
	public List findAllWords(Map paramMap) {
		//return dao.queryForList(UserSql.selectUser(), paramMap);
		return dao.queryForList(WordDeungrokQry.selectWord(), paramMap);
	}
	
	public List findAllWords2(Map paramMap) {
		//return dao.queryForList(UserSql.selectUser(), paramMap);
		return dao.queryForList(WordDeungrokQry2.selectWord(), paramMap);
	}
	
	/**
     * 단어사전 저장
     * @Author : 최성원
     * @Create : 2011년 5월 10일
     * @Description : 단어사전을 등록, 수정, 삭제 저장을 한다.
     * @Title : 단어사전저장
     * @DSDM_UML20_PROFILE_x__y_ServiceMethod_x__y_IF WordDeungrokQry.insertWord(),WordDeungrokQry.updateWord(),WordDeungrokQry.deleteWord() 
     * @stereotype ServiceMethod 
     */
	public void saveWords(GridData<WordDeungrok> gridData) {
		for (int index  = 0; index < gridData.getList().size(); index++) {
			WordDeungrok wordDeungrok = gridData.getList().get(index);
			RowStatus status = gridData.getStatusOf(index);
			if (status.equals(RowStatus.INSERT)) { // "INSERT"
				dao.update(WordDeungrokQry.insertWord(), wordDeungrok);
			}
			else if (status.equals(RowStatus.UPDATE)) { // "INSERT"
				dao.update(WordDeungrokQry.updateWord(), wordDeungrok);
			}
			else if (status.equals(RowStatus.DELETE)) { // "INSERT"
				dao.update(WordDeungrokQry.deleteWord(), wordDeungrok);
			}
			else throw new RuntimeException(
					"상태값 오류. [ 상태값 : "
					+ status
					+ " ], [ 상태옵션 : "
					+ status + " ]");
		}
	}
}
